#ifndef THREADTELNET_H
#define THREADTELNET_H

#include <QThread>
/*
  与节点的连接断开后，尝试重新连接。如果失败多次，则销毁该线程，调用deletelater()。
  需要注意的是，不该让节点从connected区域直接跳到not work区域。应该先到toconnect区域，然后再决定
  是否到notwork区域
  */
class TelnetSocket;
class ThreadTelnet : public QThread
{
    Q_OBJECT
public:
    explicit ThreadTelnet(quint16 port,QByteArray nodeIP,qint64 subAddr,QObject *parent = 0);
    ~ThreadTelnet();
    void run();

signals:
    void sigThreadDestroyed(QByteArray nodeIP,qint64 subAddr);
    //连接断开。通知主界面，将节点从connected区移到toconnect区
    void sigTelnetDisconnectedTemporarily(QByteArray nodeIP,qint64 subAddr);
    void sigTelnetConnected(QByteArray nodeIP, qint64 subAddr);
    void sigShowInfoToTextEdit(QByteArray text);
    void sigPacketReady(QByteArray packet);

    void sigPacketToNodes(QByteArray packet,qint64 destSubAddr);
    void sigShowInfoToErrorTextEdit(QByteArray text);

public slots:

private slots:
    //如果IP相符，则退出线程，并删除自己
    void slotExitThread(QByteArray nodeIP,qint64 subAddr);


private:
    quint16 telnetPort;
    QByteArray telnetIP;
    qint64 nodeSubAddr;
    TelnetSocket *telnetSocket;


};

#endif // THREADTELNET_H
